import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *

testCase = "dbshopST014_删除分类"
# 1.点击分类名称为“商品分类测试”后方的删除分类"链接
firefox = openBrowser(urlAdmin)
# 登录后台
DBshopLoginAdmin(firefox)
firefox.find_element_by_partial_link_text("添加商品分类").click()  # 进入管理分类界面
# 获取分类类名列表
s = firefox.find_elements_by_xpath('//tbody/tr/td[1]')
a = []
b = []
for i in s:
    a.append(i.text)
print(a)
# 遍历出我想要的那个类
for z in a:
    if "商品分类测试" in z:
        b.append(z)
        print(b[0])
# 过滤出我需要的ID
c = reGetString(b[0], leftBinary=r"\(ID:", rightBinary=r"\)")
print(c)
# 依据ID定位删除分类链接
firefox.find_element_by_xpath('//a[@onclick="return class_del_js(%s);"]' % c).click()
firefox.switch_to.alert.accept()  # 点击确定按钮
# 断言
try:
    if b not in a:
        writeLog("%s 测试通过" % testCase)
except:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
firefox.quit()
